Requires(T) Method (T, String)

CuttingEdge.Conditions

Returns a new ConditionValidator that allows you to validate the preconditions of the given argument.

Namespace:  CuttingEdge.Conditions
Assembly:  CuttingEdge.Conditions (in CuttingEdge.Conditions.dll)

Syntax

Visual Basic (Declaration)
Public Shared Function Requires(Of T) ( _
	value As T, _
	argumentName As String _
) As ConditionValidator(Of T)
C#
public static ConditionValidator<T> Requires<T>(
	T value,
	string argumentName
)
Visual C++
public:
generic<typename T>
static ConditionValidator<T>^ Requires(
	T value, 
	String^ argumentName
)
JavaScript
JavaScript does not support generic types or methods.

Parameters

value
Type: T
The value of the argument to validate.
argumentName
Type: System..::.String
The name of the argument to validate

Type Parameters

T
The type of the argument to validate.

Return Value

A new ConditionValidator containing the value and argumentName.

Examples

The following example shows how to use the Requires method.
 Copy Code
  using CuttingEdge.Conditions;
  
  public class Point
  {
      private readonly int x;
      private readonly int y;
      
      public Point(int x, int y)
      {
          // Throws an ArgumentOutOfRangeException when x is less than 0
          Condition.Requires(x, "x").IsGreaterOrEqual(0);
          
          // Throws an ArgumentOutOfRangeException when y is less than 0
          Condition.Requires(y, "y").IsGreaterOrEqual(0);
          
          this.x = x;
          this.y = y;
      }
      
      public int X { get { return this.x; } }
      public int Y { get { return this.y; } }
  }
  
See the ConditionValidator<(Of <(T>)>) class for more code examples.

See Also